import React from "react";

function Hook5() {
  const [count, setCount] = React.useState(0)

  React.useEffect(() => {
    console.log('开始一个定时器')
    const timer = setInterval(() => {
      setCount(count + 1)
    }, 1000)

    return () => {
      console.log('销毁老的定时器')
      clearInterval(timer)
    }
  })
  return (
    <div>
      {count}
    </div>
  )
}

export default Hook5
